<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>vue 源码探秘系列之AST抽象语法树 | 不眠</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/blog_front/favicon.ico">
    <meta name="description" content="生活不仅需要氧气，更需要勇气">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/blog_front/assets/css/0.styles.d5cfe64c.css" as="style"><link rel="preload" href="/blog_front/assets/js/app.f126fdc6.js" as="script"><link rel="preload" href="/blog_front/assets/js/3.ba154db2.js" as="script"><link rel="preload" href="/blog_front/assets/js/1.1f0d1f23.js" as="script"><link rel="preload" href="/blog_front/assets/js/18.e832171e.js" as="script"><link rel="prefetch" href="/blog_front/assets/js/10.74d752e5.js"><link rel="prefetch" href="/blog_front/assets/js/11.72f1afb7.js"><link rel="prefetch" href="/blog_front/assets/js/12.6042b8d4.js"><link rel="prefetch" href="/blog_front/assets/js/13.9684c154.js"><link rel="prefetch" href="/blog_front/assets/js/14.8b576294.js"><link rel="prefetch" href="/blog_front/assets/js/15.56073655.js"><link rel="prefetch" href="/blog_front/assets/js/16.d74732b4.js"><link rel="prefetch" href="/blog_front/assets/js/17.e3f1e2ad.js"><link rel="prefetch" href="/blog_front/assets/js/19.43a851da.js"><link rel="prefetch" href="/blog_front/assets/js/20.642c04d2.js"><link rel="prefetch" href="/blog_front/assets/js/21.00678a6a.js"><link rel="prefetch" href="/blog_front/assets/js/22.86e9d97f.js"><link rel="prefetch" href="/blog_front/assets/js/23.1578bd4e.js"><link rel="prefetch" href="/blog_front/assets/js/24.502ecba6.js"><link rel="prefetch" href="/blog_front/assets/js/25.fe7bb1b9.js"><link rel="prefetch" href="/blog_front/assets/js/26.f26725d4.js"><link rel="prefetch" href="/blog_front/assets/js/27.77a63ec4.js"><link rel="prefetch" href="/blog_front/assets/js/28.4536f711.js"><link rel="prefetch" href="/blog_front/assets/js/29.2a39afd8.js"><link rel="prefetch" href="/blog_front/assets/js/4.c0f4c928.js"><link rel="prefetch" href="/blog_front/assets/js/5.a69dfd84.js"><link rel="prefetch" href="/blog_front/assets/js/6.2d4b5bad.js"><link rel="prefetch" href="/blog_front/assets/js/7.728ad095.js"><link rel="prefetch" href="/blog_front/assets/js/8.17b33111.js"><link rel="prefetch" href="/blog_front/assets/js/9.40ab41ce.js">
    <link rel="stylesheet" href="/blog_front/assets/css/0.styles.d5cfe64c.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-999d3bb4><div data-v-999d3bb4><div id="loader-wrapper" class="loading-wrapper" data-v-2c578df8 data-v-999d3bb4 data-v-999d3bb4><div class="loader-main" data-v-2c578df8><div data-v-2c578df8></div><div data-v-2c578df8></div><div data-v-2c578df8></div><div data-v-2c578df8></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-067bd032 data-v-999d3bb4 data-v-999d3bb4><h3 class="title" data-v-067bd032 data-v-067bd032>不眠</h3> <p class="description" data-v-067bd032 data-v-067bd032>生活不仅需要氧气，更需要勇气</p> <label id="box" class="inputBox" data-v-067bd032 data-v-067bd032><input type="password" value="" data-v-067bd032> <span data-v-067bd032>Konck! Knock!</span> <button data-v-067bd032>OK</button></label> <div class="footer" data-v-067bd032 data-v-067bd032><span data-v-067bd032><i class="iconfont reco-theme" data-v-067bd032></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-067bd032>vuePress-theme-reco</a></span> <span data-v-067bd032><i class="iconfont reco-copyright" data-v-067bd032></i> <a data-v-067bd032><span data-v-067bd032>william</span>
            
          <!---->
          2022
        </a></span></div></div> <div class="hide" data-v-999d3bb4><header class="navbar" data-v-999d3bb4><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog_front/" class="home-link router-link-active"><img src="/blog_front/1.png" alt="不眠" class="logo"> <span class="site-name">不眠</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog_front/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      目录
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog_front/categories/AudioAndVideo/" class="nav-link"><i class="undefined"></i>
  AudioAndVideo
</a></li><li class="dropdown-item"><!----> <a href="/blog_front/categories/react/" class="nav-link"><i class="undefined"></i>
  react
</a></li><li class="dropdown-item"><!----> <a href="/blog_front/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/blog_front/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog_front/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog_front/docs/theme-reco/" class="nav-link"><i class="undefined"></i>
  前端工程化
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/yokeney" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-999d3bb4></div> <aside class="sidebar" data-v-999d3bb4><div class="personal-info-wrapper" data-v-e2878dae data-v-999d3bb4><img src="/blog_front/1.png" alt="author-avatar" class="personal-img" data-v-e2878dae> <h3 class="name" data-v-e2878dae>
    william
  </h3> <div class="num" data-v-e2878dae><div data-v-e2878dae><h3 data-v-e2878dae>18</h3> <h6 data-v-e2878dae>Articles</h6></div> <div data-v-e2878dae><h3 data-v-e2878dae>0</h3> <h6 data-v-e2878dae>Tags</h6></div></div> <ul class="social-links" data-v-e2878dae></ul> <hr data-v-e2878dae></div> <nav class="nav-links"><div class="nav-item"><a href="/blog_front/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      目录
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog_front/categories/AudioAndVideo/" class="nav-link"><i class="undefined"></i>
  AudioAndVideo
</a></li><li class="dropdown-item"><!----> <a href="/blog_front/categories/react/" class="nav-link"><i class="undefined"></i>
  react
</a></li><li class="dropdown-item"><!----> <a href="/blog_front/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/blog_front/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog_front/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog_front/docs/theme-reco/" class="nav-link"><i class="undefined"></i>
  前端工程化
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/yokeney" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-067bd032 data-v-999d3bb4><h3 class="title" data-v-067bd032 data-v-067bd032>vue 源码探秘系列之AST抽象语法树</h3> <!----> <label id="box" class="inputBox" data-v-067bd032 data-v-067bd032><input type="password" value="" data-v-067bd032> <span data-v-067bd032>Konck! Knock!</span> <button data-v-067bd032>OK</button></label> <div class="footer" data-v-067bd032 data-v-067bd032><span data-v-067bd032><i class="iconfont reco-theme" data-v-067bd032></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-067bd032>vuePress-theme-reco</a></span> <span data-v-067bd032><i class="iconfont reco-copyright" data-v-067bd032></i> <a data-v-067bd032><span data-v-067bd032>william</span>
            
          <!---->
          2022
        </a></span></div></div> <div data-v-999d3bb4><main class="page"><section><div class="page-title"><h1 class="title">vue 源码探秘系列之AST抽象语法树</h1> <div data-v-10e19382><i class="iconfont reco-account" data-v-10e19382><span data-v-10e19382>william</span></i> <i class="iconfont reco-date" data-v-10e19382><span data-v-10e19382>3/1/2022</span></i> <!----> <!----></div></div> <div class="theme-reco-content content__default"><h2 id="今天讲的是vue源码系列探秘-ast抽象语法树"><a href="#今天讲的是vue源码系列探秘-ast抽象语法树" class="header-anchor">#</a> <strong>今天讲的是vue源码系列探秘-AST抽象语法树</strong></h2> <p>今后会陆续更新vue 源码系列篇章。好了，废话不多说了，现在让我们直接进入正题。
</p><p></p> <p>想要搞清AST抽象语法树，前置必须要搞清楚几个知识点：
</p><p></p> <ol><li><strong>相关算法储备</strong></li> <li><strong>AST形成算法</strong></li> <li><strong>手写AST编译器</strong></li> <li><strong>手写文本解析功能</strong>
接下来我会一一先把这些知识点给大家捋一遍，现在我们先来看看什么是<strong>抽象语法树</strong></li></ol> <p><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a548a5d2c81c4caca6ac2a852aa083f7~tplv-k3u1fbpfcp-watermark.image?" alt="image.png">
模版语法直接转化为正常的HTML语法是非常困难的，这时我们需要第三者（小三）AST来完成，即：</p> <p><img src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/213f00a1045a4ae6826f594a748e4006~tplv-k3u1fbpfcp-watermark.image?" alt="image.png">
通过抽象语法树进行过渡，让编译工作变得简单。</p> <p><img src="https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a84deb04991142189243cc8eccaf613c~tplv-k3u1fbpfcp-watermark.image?" alt="image.png">
好了，现在让我们一起先来学习下相关算法储备：</p> <h2 id="相关算法储备-指针思想"><a href="#相关算法储备-指针思想" class="header-anchor">#</a> 相关算法储备-指针思想</h2> <p>这里不讲指针具体的概念了，相信同学们应该不会陌生，不熟悉的可以百度一下哦，我们直接从一道题来看看：</p> <blockquote><p>试寻找字符串中，连续重复次数最多的字符。</p> <p>'aaaabbbbbcccccccccccccdddddd'</p></blockquote> <p>怎么样，很熟悉吧，面试的时候面试题都能见到这样的题目😄，下面是代码过程，同学们可以白嫖回家运行看看：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>        <span class="token comment">// 试寻找字符串中，连续重复次数最多的字符。</span>
        <span class="token keyword">var</span> str <span class="token operator">=</span> <span class="token string">'abbbccc'</span><span class="token punctuation">;</span>
        <span class="token comment">// 指针</span>
        <span class="token keyword">var</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token keyword">var</span> j <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
        <span class="token comment">// 当前重复次数最多的次数</span>
        <span class="token keyword">var</span> maxRepeatCount <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token comment">// 重复次数最多的字符串</span>
        <span class="token keyword">var</span> maxRepeatChar <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">;</span>

        <span class="token comment">// 当i还在范围内的时候，应该继续寻找</span>
        <span class="token keyword">while</span> <span class="token punctuation">(</span>i <span class="token operator">&lt;=</span> str<span class="token punctuation">.</span>length <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">// 看i指向的字符和j指向的字符是不是不相同</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>str<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">!=</span> str<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token comment">// console.log('报！！！' + i + '和' + j + '之间的文字连续相同！！都是字母' + str[i] + '它重复了' + (j - i) + '次');</span>
                <span class="token comment">// 和当前重复次数最多的进行比较</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>j <span class="token operator">-</span> i <span class="token operator">&gt;</span> maxRepeatCount<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token comment">// 如果当前文字重复次数（j - i）超过了此时的最大值</span>
                    <span class="token comment">// 就让它成为最大值</span>
                    maxRepeatCount <span class="token operator">=</span> j <span class="token operator">-</span> i<span class="token punctuation">;</span>
                    <span class="token comment">// 将i指针指向的字符存为maxRepeatChar</span>
                    maxRepeatChar <span class="token operator">=</span> str<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
                <span class="token comment">// 让指针i追上指针j</span>
                i <span class="token operator">=</span> j<span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token comment">// 不管相不相同，j永远要后移</span>
            j<span class="token operator">++</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token comment">// 循环结束之后，就可以输出答案了</span>
            console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>maxRepeatChar <span class="token operator">+</span> <span class="token string">'重复了'</span> <span class="token operator">+</span> maxRepeatCount <span class="token operator">+</span> <span class="token string">'次，是最多的连续重复字符'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br></div></div><p>好了，让我们再来看看另一个知识点：<strong>递归</strong></p> <h2 id="递归"><a href="#递归" class="header-anchor">#</a> 递归</h2> <p>这里也不讲基础概念了，直接来一刀面试题</p> <blockquote><p>试输出斐波那契数列的前10项，即1、1、2、3、5、8、13、21、34、55。然后请思
考，代码是否有大量重复的计算？应该如何解决重复计算的问题？
这里也直接贴代码了</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 试输出斐波那契数列的前10项，即1、1、2、3、5、8、13、21、34、55</span>

        <span class="token comment">// 缓存对象</span>
        <span class="token keyword">var</span> cache <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>

        <span class="token comment">// 创建一个函数，功能是返回下标为n的这项的数字</span>
        <span class="token keyword">function</span> <span class="token function">fib</span><span class="token punctuation">(</span><span class="token parameter">n</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">// 判断缓存对象中有没有这个值，如果有，直接用</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>cache<span class="token punctuation">.</span><span class="token function">hasOwnProperty</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">return</span> cache<span class="token punctuation">[</span>n<span class="token punctuation">]</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token comment">// 缓存对象没有这个值</span>
            <span class="token comment">// 看下标n是不是0或者是不是1，如果是，就返回常数1</span>
            <span class="token comment">// 如果不是，就递归</span>
            <span class="token keyword">var</span> v <span class="token operator">=</span> n <span class="token operator">==</span> <span class="token number">0</span> <span class="token operator">||</span> n <span class="token operator">==</span> <span class="token number">1</span> <span class="token operator">?</span> <span class="token number">1</span> <span class="token operator">:</span> <span class="token function">fib</span><span class="token punctuation">(</span>n <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token function">fib</span><span class="token punctuation">(</span>n <span class="token operator">-</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">// 写入缓存。也就是说，每算一个值，就要把这个值存入缓存对象。</span>
            cache<span class="token punctuation">[</span>n<span class="token punctuation">]</span> <span class="token operator">=</span> v<span class="token punctuation">;</span>
            <span class="token keyword">return</span> v<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> <span class="token number">9</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">fib</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><p>上面的代码我做了缓存优化的，感兴趣的同学可以深入了解一下，但这普通的递归远没有达到想要的程度，现在我们要把他转换成这种形式的结构</p> <p><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/5396cb293c8841ebbf91135fc40b1310~tplv-k3u1fbpfcp-watermark.image?" alt="image.png">
这里也直接贴上去了</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 转换数组的形式[1, 2, 3, [4, 5]]要变为这样的对象：</span>
        <span class="token comment">// {</span>
        <span class="token comment">//     chidren: [</span>
        <span class="token comment">//         {</span>
        <span class="token comment">//             value: 1</span>
        <span class="token comment">//         },</span>
        <span class="token comment">//         {</span>
        <span class="token comment">//             value: 2</span>
        <span class="token comment">//         },</span>
        <span class="token comment">//         {</span>
        <span class="token comment">//             value: 3</span>
        <span class="token comment">//         },</span>
        <span class="token comment">//         {</span>
        <span class="token comment">//             children: [</span>
        <span class="token comment">//                 {</span>
        <span class="token comment">//                     {</span>
        <span class="token comment">//                         value: 4</span>
        <span class="token comment">//                     },</span>
        <span class="token comment">//                     {</span>
        <span class="token comment">//                         value: 5</span>
        <span class="token comment">//                     }</span>
        <span class="token comment">//                 }</span>
        <span class="token comment">//             ]</span>
        <span class="token comment">//         }</span>
        <span class="token comment">//     ]</span>
        <span class="token comment">// }</span>

        <span class="token comment">// 测试数组</span>
        <span class="token keyword">var</span> arr <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">6</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">9</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

        <span class="token comment">// 转换函数，写法1</span>
        <span class="token comment">// function convert(arr) {</span>
        <span class="token comment">//     // 准备一个结果数组</span>
        <span class="token comment">//     var result = [];</span>
        <span class="token comment">//     // 遍历传入的arr的每一项</span>
        <span class="token comment">//     for (let i = 0; i &lt; arr.length; i++) {</span>
        <span class="token comment">//         // 如果遍历到的数字是number，直接放进入</span>
        <span class="token comment">//         if (typeof arr[i] == 'number') {</span>
        <span class="token comment">//             result.push({</span>
        <span class="token comment">//                 value: arr[i]</span>
        <span class="token comment">//             });</span>
        <span class="token comment">//         } else if (Array.isArray(arr[i])) {</span>
        <span class="token comment">//             // 如果遍历到的这项是数组，那么就递归</span>
        <span class="token comment">//             result.push({</span>
        <span class="token comment">//                 children: convert(arr[i])</span>
        <span class="token comment">//             });</span>
        <span class="token comment">//         }</span>
        <span class="token comment">//     }</span>
        <span class="token comment">//     return result;</span>
        <span class="token comment">// }</span>

        <span class="token comment">// 转换函数写法2，参数不是arr这个词语，而是item，意味着现在item可能是数组，也可能是数字</span>
        <span class="token comment">// 即，写法1的递归次数要大大小于写法2。因为写法2中，遇见什么东西都要递归一下。</span>
        <span class="token keyword">function</span> <span class="token function">convert</span><span class="token punctuation">(</span><span class="token parameter">item</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> item <span class="token operator">==</span> <span class="token string">'number'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token comment">// 如果传进来的参数是数字</span>
                <span class="token keyword">return</span> <span class="token punctuation">{</span>
                    <span class="token literal-property property">value</span><span class="token operator">:</span> item
                <span class="token punctuation">}</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>Array<span class="token punctuation">.</span><span class="token function">isArray</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token comment">// 如果传进来的参数是数组</span>
                <span class="token keyword">return</span> <span class="token punctuation">{</span>
                    <span class="token literal-property property">children</span><span class="token operator">:</span> item<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token parameter">_item</span> <span class="token operator">=&gt;</span> <span class="token function">convert</span><span class="token punctuation">(</span>_item<span class="token punctuation">)</span><span class="token punctuation">)</span>
                <span class="token punctuation">}</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">var</span> o <span class="token operator">=</span> <span class="token function">convert</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>o<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br></div></div><p>好了，到这里已经学习了，<strong>指针的思</strong>想和<strong>递归</strong>，相信你已经有点感觉了，现在来点经典的数据结构：<strong>栈</strong>，这里先给大家普及下问什么要用栈数据结构，<strong>vue在词法分析的时候要用到栈数据结构</strong>
，现在也是用一道面试题来缕缕：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">//试编写“智能重复”smartRepeat函数，实现：</span>
将<span class="token number">3</span><span class="token punctuation">[</span>abc<span class="token punctuation">]</span>变为abcabcabc
将<span class="token number">3</span><span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token number">2</span><span class="token punctuation">[</span>b<span class="token punctuation">]</span><span class="token punctuation">]</span>变为aabbaabbaabb
将<span class="token number">2</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token number">3</span><span class="token punctuation">[</span>b<span class="token punctuation">]</span><span class="token number">2</span><span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">[</span>c<span class="token punctuation">]</span><span class="token number">4</span><span class="token punctuation">[</span>d<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">]</span>变为abbbcccddddcccddddabbbcccddddcccdddd
 不用考虑输入字符串是非法的情况，比如：
<span class="token number">2</span><span class="token punctuation">[</span>a3<span class="token punctuation">[</span>b<span class="token punctuation">]</span><span class="token punctuation">]</span>是错误的，应该补一个<span class="token number">1</span>，即<span class="token number">2</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token number">3</span><span class="token punctuation">[</span>b<span class="token punctuation">]</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span>abc<span class="token punctuation">]</span>是错误的，应该补一个<span class="token number">1</span>，即<span class="token number">1</span><span class="token punctuation">[</span>abc<span class="token punctuation">]</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>这里先说一下解题思路：</p> <p><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d78d8e87026a4dfdb1987590e70025e2~tplv-k3u1fbpfcp-watermark.image?" alt="image.png">
不说了，直接贴代码</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 试编写“智能重复”smartRepeat函数，实现：     </span>
        <span class="token comment">// 将3[abc]变为abcabcabc</span>
        <span class="token comment">// 将3[2[a]2[b]]变为aabbaabbaabb  </span>
        <span class="token comment">// 将2[1[a]3[b]2[3[c]4[d]]]变为abbbcccddddcccddddabbbcccddddcccdddd</span>

        <span class="token keyword">function</span> <span class="token function">smartRepeat</span><span class="token punctuation">(</span><span class="token parameter">templateStr</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">// 指针</span>
            <span class="token keyword">var</span> index <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
            <span class="token comment">// 栈1，存放数字</span>
            <span class="token keyword">var</span> stack1 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
            <span class="token comment">// 栈2，存放临时字符串</span>
            <span class="token keyword">var</span> stack2 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
            <span class="token comment">// 剩余部分</span>
            <span class="token keyword">var</span> rest <span class="token operator">=</span> templateStr<span class="token punctuation">;</span>

            <span class="token keyword">while</span> <span class="token punctuation">(</span>index <span class="token operator">&lt;</span> templateStr<span class="token punctuation">.</span>length <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token comment">// 剩余部分</span>
                rest <span class="token operator">=</span> templateStr<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span>index<span class="token punctuation">)</span><span class="token punctuation">;</span>

                <span class="token comment">// 看当前剩余部分是不是以数字和[开头</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^\d+\[</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>rest<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token comment">// 得到这个数字</span>
                    <span class="token keyword">let</span> times <span class="token operator">=</span> <span class="token function">Number</span><span class="token punctuation">(</span>rest<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^(\d+)\[</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token comment">// 就把数字压栈，把空字符串压栈</span>
                    stack1<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span>times<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    stack2<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token comment">// 让指针后移，times这个数字是多少位就后移多少位加1位。</span>
                    <span class="token comment">// 为什么要加1呢？加的1位是[。</span>
                    index <span class="token operator">+=</span> times<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>length <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^\w+\]</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>rest<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token comment">// 如果这个字符是字母，那么此时就把栈顶这项改为这个字母</span>
                    <span class="token keyword">let</span> word <span class="token operator">=</span> rest<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^(\w+)\]</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
                    stack2<span class="token punctuation">[</span>stack2<span class="token punctuation">.</span>length <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">=</span> word<span class="token punctuation">;</span>
                    <span class="token comment">// 让指针后移，word这个词语是多少位就后移多少位</span>
                    index <span class="token operator">+=</span> word<span class="token punctuation">.</span>length<span class="token punctuation">;</span>
                <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>rest<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token string">']'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token comment">// 如果这个字符是]，那么就①将stack1弹栈，②stack2弹栈，③把字符串栈的新栈顶的元素重复刚刚弹出的那个字符串指定次数拼接到新栈顶上。</span>
                    <span class="token keyword">let</span> times <span class="token operator">=</span> stack1<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token keyword">let</span> word <span class="token operator">=</span> stack2<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token comment">// repeat是ES6的方法，比如'a'.repeat(3)得到'aaa'</span>
                    stack2<span class="token punctuation">[</span>stack2<span class="token punctuation">.</span>length <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">+=</span> word<span class="token punctuation">.</span><span class="token function">repeat</span><span class="token punctuation">(</span>times<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    index<span class="token operator">++</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>

                console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>index<span class="token punctuation">,</span> stack1<span class="token punctuation">,</span> stack2<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>

            <span class="token comment">// while结束之后，stack1和stack2中肯定还剩余1项。返回栈2中剩下的这一项，重复栈1中剩下的这1项次数，组成的这个字符串。如果剩的个数不对，那就是用户的问题，方括号没有闭合。</span>
            <span class="token keyword">return</span> stack2<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">repeat</span><span class="token punctuation">(</span>stack1<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">var</span> result <span class="token operator">=</span> <span class="token function">smartRepeat</span><span class="token punctuation">(</span><span class="token string">'3[2[3[a]1[b]]4[d]]'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>result<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br></div></div><p>这里过一下栈实现字符串smartRepeat函数，是因为建立抽象语法树要用到栈顶的操作过程所以这里带大家过一下面试经常考的面试题，很有价值意义。
新建一个index.html文件演示一下，代码如下：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> parse <span class="token keyword">from</span> <span class="token string">'./parse.js'</span><span class="token punctuation">;</span>

<span class="token keyword">var</span> templateString <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">&lt;div&gt;
    &lt;h3 class=&quot;aa bb cc&quot; data-n=&quot;7&quot; id=&quot;mybox&quot;&gt;你好&lt;/h3&gt;
    &lt;ul&gt;
        &lt;li&gt;A&lt;/li&gt;
        &lt;li&gt;B&lt;/li&gt;
        &lt;li&gt;C&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span>

<span class="token keyword">const</span> ast <span class="token operator">=</span> <span class="token function">parse</span><span class="token punctuation">(</span>templateString<span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>ast<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><p>新建parse.js解析模版</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> parseAttrsString <span class="token keyword">from</span> <span class="token string">'./parseAttrsString.js'</span><span class="token punctuation">;</span>

<span class="token comment">// parse函数，主函数</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">templateString</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 指针</span>
    <span class="token keyword">var</span> index <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token comment">// 剩余部分</span>
    <span class="token keyword">var</span> rest <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">;</span>
    <span class="token comment">// 开始标记</span>
    <span class="token keyword">var</span> startRegExp <span class="token operator">=</span> <span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^\&lt;([a-z]+[1-6]?)(\s[^\&lt;]+)?\&gt;</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">;</span>
    <span class="token comment">// 结束标记</span>
    <span class="token keyword">var</span> endRegExp <span class="token operator">=</span> <span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^\&lt;\/([a-z]+[1-6]?)\&gt;</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">;</span>
    <span class="token comment">// 抓取结束标记前的文字</span>
    <span class="token keyword">var</span> wordRegExp <span class="token operator">=</span> <span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^([^\&lt;]+)\&lt;\/[a-z]+[1-6]?\&gt;</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">;</span>
    <span class="token comment">// 准备两个栈</span>
    <span class="token keyword">var</span> stack1 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword">var</span> stack2 <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">{</span> <span class="token string-property property">'children'</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

    <span class="token keyword">while</span> <span class="token punctuation">(</span>index <span class="token operator">&lt;</span> templateString<span class="token punctuation">.</span>length <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        rest <span class="token operator">=</span> templateString<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span>index<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// console.log(templateString[index]);</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>startRegExp<span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>rest<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">// 识别遍历到的这个字符，是不是一个开始标签</span>
            <span class="token keyword">let</span> tag <span class="token operator">=</span> rest<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span>startRegExp<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
            <span class="token keyword">let</span> attrsString <span class="token operator">=</span> rest<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span>startRegExp<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
            <span class="token comment">// console.log('检测到开始标记', tag);</span>
            <span class="token comment">// 将开始标记推入栈1中</span>
            stack1<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span>tag<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">// 将空数组推入栈2中</span>
            stack2<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token string-property property">'tag'</span><span class="token operator">:</span> tag<span class="token punctuation">,</span> <span class="token string-property property">'children'</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token string-property property">'attrs'</span><span class="token operator">:</span> <span class="token function">parseAttrsString</span><span class="token punctuation">(</span>attrsString<span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">// 得到attrs字符串的长度</span>
            <span class="token keyword">const</span> attrsStringLength <span class="token operator">=</span> attrsString <span class="token operator">!=</span> <span class="token keyword">null</span> <span class="token operator">?</span> attrsString<span class="token punctuation">.</span>length <span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">;</span>
            <span class="token comment">// 指针移动标签的长度加2再加attrString的长度，为什么要加2呢？因为&lt;&gt;也占两位</span>
            index <span class="token operator">+=</span> tag<span class="token punctuation">.</span>length <span class="token operator">+</span> <span class="token number">2</span> <span class="token operator">+</span> attrsStringLength<span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>endRegExp<span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>rest<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">// 识别遍历到的这个字符，是不是一个结束标签</span>
            <span class="token keyword">let</span> tag <span class="token operator">=</span> rest<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span>endRegExp<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
            <span class="token comment">// console.log('检测到结束标记', tag);</span>
            <span class="token keyword">let</span> pop_tag <span class="token operator">=</span> stack1<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">// 此时，tag一定是和栈1顶部的是相同的</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>tag <span class="token operator">==</span> pop_tag<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">let</span> pop_arr <span class="token operator">=</span> stack2<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>stack2<span class="token punctuation">.</span>length <span class="token operator">&gt;</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    stack2<span class="token punctuation">[</span>stack2<span class="token punctuation">.</span>length <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">.</span>children<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span>pop_arr<span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">Error</span><span class="token punctuation">(</span>pop_tag <span class="token operator">+</span> <span class="token string">'标签没有封闭！！'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token comment">// 指针移动标签的长度加3，为什么要加2呢？因为&lt;/&gt;也占3位</span>
            index <span class="token operator">+=</span> tag<span class="token punctuation">.</span>length <span class="token operator">+</span> <span class="token number">3</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>wordRegExp<span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>rest<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">// 识别遍历到的这个字符，是不是文字，并别不能是全空</span>
            <span class="token keyword">let</span> word <span class="token operator">=</span> rest<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span>wordRegExp<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
            <span class="token comment">// 看word是不是全是空</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^\s+$</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>word<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token comment">// 不是全是空 </span>
                <span class="token comment">// console.log('检测到文字', word);</span>
                <span class="token comment">// 改变此时stack2栈顶元素中</span>
                stack2<span class="token punctuation">[</span>stack2<span class="token punctuation">.</span>length <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">.</span>children<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token string-property property">'text'</span><span class="token operator">:</span> word<span class="token punctuation">,</span> <span class="token string-property property">'type'</span><span class="token operator">:</span> <span class="token number">3</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token comment">// 指针移动标签的长度加3，为什么要加2呢？因为&lt;/&gt;也占3位</span>
            index <span class="token operator">+=</span> word<span class="token punctuation">.</span>length<span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
            index<span class="token operator">++</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// 此时stack2就是我们之前默认放置的一项了，此时要返回这一项的children即可</span>
    <span class="token keyword">return</span> stack2<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>children<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br></div></div><p>还有的就是模版中属性attr的处理：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 把attrsString变为数组返回</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">attrsString</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>attrsString <span class="token operator">==</span> <span class="token keyword">undefined</span><span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>attrsString<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment">// 当前是否在引号内</span>
    <span class="token keyword">var</span> isYinhao <span class="token operator">=</span> <span class="token boolean">false</span>
    <span class="token comment">// 断点</span>
    <span class="token keyword">var</span> point <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token comment">// 结果数组</span>
    <span class="token keyword">var</span> result <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

    <span class="token comment">// 遍历attrsString，而不是你想的用split()这种暴力方法</span>
    <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> attrsString<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">let</span> char <span class="token operator">=</span> attrsString<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>char <span class="token operator">==</span> <span class="token string">'&quot;'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            isYinhao <span class="token operator">=</span> <span class="token operator">!</span>isYinhao<span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>char <span class="token operator">==</span> <span class="token string">' '</span> <span class="token operator">&amp;&amp;</span> <span class="token operator">!</span>isYinhao<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">// 遇见了空格，并且不在引号中</span>
            console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^\s*$</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">.</span><span class="token function">test</span><span class="token punctuation">(</span>attrsString<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span>point<span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                result<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span>attrsString<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span>point<span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                point <span class="token operator">=</span> i<span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token comment">// 循环结束之后，最后还剩一个属性k=&quot;v&quot;</span>
    result<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span>attrsString<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span>point<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">// 下面的代码功能是，将[&quot;k=v&quot;,&quot;k=v&quot;,&quot;k=v&quot;]变为[{name:k, value:v}, {name:k, value:v}, {name:k,value:v}];</span>
    result <span class="token operator">=</span> result<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token parameter">item</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
        <span class="token comment">// 根据等号拆分</span>
        <span class="token keyword">const</span> o <span class="token operator">=</span> item<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^(.+)=&quot;(.+)&quot;$</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token punctuation">{</span>
            <span class="token literal-property property">name</span><span class="token operator">:</span> o<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token literal-property property">value</span><span class="token operator">:</span> o<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">return</span> result<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br></div></div><p>下面是代码链接：</p> <div class="custom-block danger"><p class="title"></p><p>https://gitee.com/yokeney/vue--abstract-syntax-tree</p></div><p>总结：</p> <div class="custom-block tip"><p class="title"></p><p>在写主函数 <strong><code>parse.js</code></strong> 的时候，使用到算法就是栈，利用到了算法储备中栈的思想，我们在探秘vue源码的过程就是在学习算法的过程，算法的思想实现，这也是有助于你编程水平的提高</p></div><div class="custom-block tip"><p class="title"></p><p>栈的思维在对模板字符串进行解析的时候很有用，能对嵌套 HTML 进行快速的解析</p></div></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">3/3/2022, 8:50:33 AM</span></div></footer> <!----> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-92abcef6><li class="level-2" data-v-92abcef6><a href="/blog_front/blogs/vue/2022/0102.html#今天讲的是vue源码系列探秘-ast抽象语法树" class="sidebar-link reco-side-今天讲的是vue源码系列探秘-ast抽象语法树" data-v-92abcef6>今天讲的是vue源码系列探秘-AST抽象语法树</a></li><li class="level-2" data-v-92abcef6><a href="/blog_front/blogs/vue/2022/0102.html#相关算法储备-指针思想" class="sidebar-link reco-side-相关算法储备-指针思想" data-v-92abcef6>相关算法储备-指针思想</a></li><li class="level-2" data-v-92abcef6><a href="/blog_front/blogs/vue/2022/0102.html#递归" class="sidebar-link reco-side-递归" data-v-92abcef6>递归</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-a008c6ba data-v-a008c6ba><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-a008c6ba><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-a008c6ba></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-a008c6ba></path></svg></div></div></div>
    <script src="/blog_front/assets/js/app.f126fdc6.js" defer></script><script src="/blog_front/assets/js/3.ba154db2.js" defer></script><script src="/blog_front/assets/js/1.1f0d1f23.js" defer></script><script src="/blog_front/assets/js/18.e832171e.js" defer></script>
  </body>
</html>
